Refactoring the code

IntelliJ IDEA offers a variety of Java code refactorings.

Available code refactorings:

Package and Class Migration

The migration feature allows to rename references to a given set of packages and classes.  You have to specify a set of modifications that will be applied sequentially. IDEA will process the given set in specified order and change references to the packages and classes in the whole project. It does not modify the elements themselves but their usages only. This means that the elements from the map may even be not available in the project.

This feature is mostly useful when you need to update your source code according to some third-party code (for example, some class library) changes.
For instance, you can update your source code using Swing 1.0.3 to work with Swing 1.1. In order to do it, all references to com.sun.java.swing.* package with all subpackages should be renamed to javax.swing.*. At the same time, all usages of packages com.sun.java.swing.plaf.windows and com.sun.java.swing.plaf.motif should not be changed.

How to migrate

  1. Select the "Refactoring | Migrate..." main menu item.
  2. In the dialog you can select a migration map to proceed. The selected migration map defines which class and package names are to be changed. To see the selected migration set or to change it, press the "Edit..." button. To create a new migration set, press the "New..." button.
  3. To continue, press the "Find usages" button.
  4. All found usages will be shown at the bottom part of the main window in the search result window.
  5. You can browse the results and see the places in your code that will be changed during the migration process.
  6. To perform the actual migration, press the "Do Migrate" button at the bottom of the panel (or press Alt-D). You may also cancel the operation by pressing the "Cancel" button or Alt-C.

Where migration sets are saved

All migration sets are saved in the "migration" subdirectory of the program installation directory. Each set is saved in a .xml file. The migration set's name defines the name of the file.